package com.qiyee.dalligent.module.customer.api;

import com.qiyee.dalligent.common.utils.FileDownloadUtils;
import com.qiyee.dalligent.common.utils.UploadUtil;
import com.qiyee.dalligent.module.base.BaseResponse;
import com.qiyee.dalligent.module.base.FileBean;
import com.qiyee.dalligent.module.customer.entity.CustomerUser;
import com.qiyee.dalligent.module.customer.service.CustomerUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("customer")
@Api(tags = "用户服务")
public class CustomerUserApi {
    @Autowired
    private CustomerUserService customerUserService;

    @ApiOperation(value = "获取list",response = CustomerUser.class)
    @GetMapping("/list")
    public BaseResponse getList(){
        return BaseResponse.success(customerUserService.getCustomerUserList());
    }
    @ApiOperation(value = "保存用户信息",response = Boolean.class)
    @PostMapping("/save")
    public BaseResponse saveCustomerUser(@RequestBody CustomerUser customerUser){
        return BaseResponse.success(customerUserService.addCustomerUser(customerUser));
    }

    @ApiOperation(value = "保存用户简历文件",response = FileBean.class)
    @PostMapping("/uploadFile")
    public BaseResponse uploadResumeFile(@RequestParam("file") MultipartFile file){
        return BaseResponse.success(UploadUtil.uploadResumeFile(file));
    }
    @ApiOperation(value = "下载用户简历文件")
    @GetMapping("/downloadFile")
    public void downloadFile(HttpServletResponse response,@RequestParam("fileName") String fileName){
        FileDownloadUtils.downLoadResume(response,fileName);
    }
}
